﻿using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Domain.RBACFile;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.Commands.CottagesCommands
{
    public class EmployeeSearchHander : IRequestHandler<EmployeeSearchCommand, ResultT<Employee>>
    {

        private readonly IBaseRepository<Employee> employeeRepository;
        private readonly ILogger<EmployeeSearchHander> logger;

        public EmployeeSearchHander(IBaseRepository<Employee> employeeRepository, ILogger<EmployeeSearchHander> logger)
        {
            this.employeeRepository = employeeRepository;
            this.logger = logger;
        }

        /// <summary>
        /// 获取负责人（生产人）
        /// </summary>
        /// <param name="request">获取负责人（生产人）请求对象</param>
        /// <param name="cancellationToken"></param>
        /// <returns>获取负责人（生产人）响应对象</returns>
        public async Task<ResultT<Employee>> Handle(EmployeeSearchCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<Employee>();
                var list =  employeeRepository.GetAll().ToList();
                result.Data =  list;
                logger.LogInformation("获取栋舍分类信息方法调用成功");
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("获取栋舍分类信息方法调用出错" + ex);
                throw;
            }
        }
    }
}
